package gob.minedu.capacitacion.cxa.dao.ibatisImpl;

/**
 * @author pedro rios
 * @date 04/02/14
 */

import gob.minedu.capacitacion.cxa.bean.TallerBean;
import gob.minedu.capacitacion.cxa.dao.ibatis.TallerDAO;
import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;


public class TallerDAOMysql extends SqlMapClientDaoSupport implements TallerDAO {

	@Override
	public List<TallerBean> getTalleresActivos() {
		try{
			return (List<TallerBean>)getSqlMapClientTemplate().queryForList("getTalleresActivos");
		}catch (Exception e) {
			e.printStackTrace();
			System.out.println("Error en el ibatis - method getTalleresActivos()");
			return null;
		}
	}

	@Override
	public boolean updateFechasTaller(TallerBean obj) {
		try {
			 getSqlMapClientTemplate().update("updateFechasTaller",obj);	
			 return true;
		} catch (RuntimeException e) {
			e.printStackTrace();
			System.out.println("Error en el ibatis - method updateTaller()");
			return false;
		}
	}
	
	@Override
	public String getCodigoTallerNew() {
		try{
			 return (String) getSqlMapClientTemplate().queryForObject("getCodigoTallerNew");
	
		 }catch (Exception e) {
			e.printStackTrace();
			System.out.println("Error en el ibatis - method getCodigoTallerNew()");
			return null;
		}
	}

	@Override
	public boolean insertTaller(TallerBean obj) {
		try {
			 getSqlMapClientTemplate().insert("insertTaller",obj);	
			 return true;
		} catch (RuntimeException e) {
			e.printStackTrace();
			System.out.println("Error en el ibatis - method insertTaller()");
			return false;
		}
	}

	@Override
	public TallerBean getTallerById(Long idTaller) {
		try {
			return (TallerBean) getSqlMapClientTemplate().queryForObject("getTallerById",idTaller);	
		} catch (RuntimeException e) {
			e.printStackTrace();
			System.out.println("Error en el ibatis - method getTallerById()");
			return null;
		}
	}

	@Override
	public boolean updateTaller(TallerBean obj) {
		try {
			 getSqlMapClientTemplate().update("updateTaller",obj);	
			 return true;
		} catch (RuntimeException e) {
			e.printStackTrace();
			System.out.println("Error en el ibatis - method updateTaller()");
			return false;
		}
	}
	
	
	
	public boolean deleteTaller(Long idTaller) {
		
		try{
			 getSqlMapClientTemplate().update("deleteTaller",idTaller);			
			return true;
		}catch (RuntimeException e) {
			e.printStackTrace();
			System.out.println("Error en el ibatis - method insertTaller()");
			return false;
		}
		
	}	
	


	
}